package cn.tedu.tmall.front.mall.controller;

import cn.tedu.tmall.common.pojo.po.GoodsSearchPO;
import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.web.JsonResult;
import cn.tedu.tmall.front.mall.service.IGoodsService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
@Api(tags = "1. 商品管理")
@Validated
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    @ApiOperation("搜索商品")
    @ApiOperationSupport(order = 600)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词", required = true),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int")
    })
    @GetMapping("/search")
    public JsonResult search(String keyword, Integer page) {
        Integer pageNum = page == null ? 1 : page;
        PageData<GoodsSearchPO> pageData = goodsService.search(keyword, pageNum, 20);
        return JsonResult.ok(pageData);
    }

}
